<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class EventHandler extends WechatHandler {

    public function run($postObj) {
        // 订阅事件
        if ($postObj->Event == "subscribe") {
            if (preg_match("/qrscene\_/is", $postObj->EventKey)) {
                // 推广 二维码扫描订阅事件
                $qrscene = (int) preg_replace("/qrscene\_/is", "", $postObj->EventKey) + 100000;
                $this->wc->Db->query(sprintf("REPLACE INTO client_token (openid,token_time,qrscene) VALUES ('%s',NOW(),'%s');", $this->openID, $qrscene));
            }
            $this->wc->echoGmess(41);
        }

        if ($postObj->Event == "SCAN" && preg_match("/8814/is", $postObj->EventKey)) {
            if (preg_match("/qrscene/is", $postObj->EventKey)) {
                $this->wc->loginQrcodeScaned(preg_replace("/qrscene\_/is", "", $postObj->EventKey), $this->openID);
            } else {
                $this->wc->loginQrcodeScaned($postObj->EventKey, $this->openID);
            }
        }

        switch ($postObj->EventKey) {
            case 'ABOUT-US' :
                $this->wc->echoGmess(39);
            case 'PROXY' :
                $this->wc->echoGmess(40);
                break;
            case 'RECOMMENT' : 
                $this->wc->echoGmess(38);
                break;
        }
    }

}
